<template>
    <div class="pop-remaining-win">
        <div class="analysisBox">
            <div class="analysisContent">
                <div class="analysis-card">
                    <div class="card-title">服务项目数据分析</div>
                    <div class="card-content">
                        <div class="data-grid">
                            <div class="data-item flex_between">
                                <div class="data-icon">
                                    <i class="icon-shopping"></i>
                                </div>
                                <div class="flex_row">
                                    <div class="data-label mr10">消费次数</div>
                                    <div class="data-value">{{ analysisData.od_number || 0.0 }}</div>
                                </div>
                            </div>
                            <div class="data-item flex_between">
                                <div class="data-icon">
                                    <i class="icon-money"></i>
                                </div>
                                <div class="flex_row">
                                    <div class="data-label mr10">消费金额（元）</div>
                                    <div class="data-value">{{ analysisData.od_amount || 0 }}</div>
                                </div>
                            </div>
                            <div class="data-item flex_between">
                                <div class="data-icon">
                                    <i class="icon-usage"></i>
                                </div>
                                <div class="flex_row">
                                    <div class="data-label mr10">消耗次数</div>
                                    <div class="data-value">{{ analysisData.xh_number || 0.0 }}</div>
                                </div>
                            </div>
                            <div class="data-item flex_between">
                                <div class="data-icon">
                                    <i class="icon-cost"></i>
                                </div>
                                <div class="flex_row">
                                    <div class="data-label mr10">消耗金额（元）</div>
                                    <div class="data-value">{{ analysisData.xh_amount || 0 }}</div>
                                </div>
                            </div>
                        </div>
                        <div class="data-section">
                            <h3 class="section-title">最近消费记录</h3>
                            <div class="data-list">
                                <div class="list-item">
                                    <span class="list-label">最近消费日期：</span>
                                    <span class="list-value">{{ analysisData.od_timestr || '-' }}</span>
                                </div>
                                <div class="list-item">
                                    <span class="list-label">最近消费距今：</span>
                                    <span class="list-value">{{ analysisData.od_day_ce || '-' }}</span>
                                </div>
                                <div class="list-item">
                                    <span class="list-label">最近消耗日期：</span>
                                    <span class="list-value">{{ analysisData.mb_timestr || '-' }}</span>
                                </div>
                                <div class="list-item">
                                    <span class="list-label">最近消耗距今：</span>
                                    <span class="list-value">{{ analysisData.md_day_ce || '-' }}</span>
                                </div>
                            </div>
                        </div>
                        <div class="data-section">
                            <h3 class="section-title">客单价分析</h3>
                            <div class="price-grid">
                                <div class="price-item flex_between">
                                    <div class="price-label">最高消费客单价（元）</div>
                                    <div class="price-value">{{ analysisData.od_max_price || 0 }}</div>
                                </div>
                                <div class="price-item flex_between">
                                    <div class="price-label">平均消费客单价（元）</div>
                                    <div class="price-value">{{ analysisData.od_amount_avg || 0 }}</div>
                                </div>
                                <div class="price-item flex_between">
                                    <div class="price-label">平均消耗客单价（元）</div>
                                    <div class="price-value">{{ analysisData.mb_amount_ave || 0 }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import staticConst from "@/js/const/StaticConst.js";
import config from "@/js/conf/Config.js";
import empty from "@/components/comm/empty.vue";
import https from "@/js/https/Https.js";
var pageSize = staticConst.PAGE_SIZE;
var pageNo = 0;

export default {
    components: {
        empty,
    },
    name: "intelligentAnalysis",
    props: {
        customId: {
            type: String,
            default: ''
        },
        customInfo: {
            type: Object,
            default: () => { }
        },
    },
    watch: {
        customInfo(newVal) {
            if (newVal) {
                console.log('客户customInfo===:', newVal);
                // this.initAnalyInfoData();
            }
        }
    },
    data() {
        return {
            analysisData: {}
        };
    },
    methods: {
        initAnalyInfoData() {
            // 智能分析
            this.getAnalyInfo();
        },

        /*****智能分析*****/
        getAnalyInfo() {
            let that = this;
            let param = {
                id: this.customId,
                pnum: pageSize,
                pfrom: pageNo * pageSize,
            };
            https.customAnalyInfo(param, back);
            function back(data) {
                if (!data) return;
                if (data.status == 1) {
                    if (data.data) {
                        data = data.data;
                        that.analysisData = data?.info || {};
                    } else {
                        that.analysisData = {};
                    }
                }
            }
        },

        // 可以添加一个加载分析数据的方法
        loadAnalysisData() {
            // 实际项目中可能需要调用API获取数据
            console.log('加载分析数据，客户ID:', this.customId);
        }
    },
    mounted() {
        this.initAnalyInfoData();
    }
};
</script>

<style lang="scss" scoped>
.reservationis-dialog-box {
    ::v-deep .el-dialog__body {
        padding: 0;
    }
}

.pop-remaining-win {
    padding-top: 5px;

    ::v-deep .el-dialog__body {
        padding-top: 0 !important;
    }
}

.analysisBox {
    width: 100%;
}

.analysisContent {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.analysis-card {
    background: #ffffff;
    border-radius: 6px;
    padding: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
    transition: all 0.3s ease;

    &:hover {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
        transform: translateY(-2px);
    }
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 2px solid #f3f4f6;
}

.card-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* 数据网格样式 */
.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.data-item {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    transition: all 0.3s ease;
    border: 1px solid #e2e8f0;
    position: relative;
    overflow: hidden;

    &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 4px;
        height: 100%;
        background: linear-gradient(to bottom, #3b82f6, #60a5fa);
    }

    &:hover {
        transform: translateY(-3px);
        box-shadow: 0 6px 20px rgba(59, 130, 246, 0.15);
        border-color: #93c5fd;
    }
}

.data-icon {
    width: 50px;
    height: 50px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #3b82f6;
}

/* 使用伪元素模拟图标 */
.icon-shopping::before {
    content: "🛒";
}

.icon-money::before {
    content: "💰";
}

.icon-usage::before {
    content: "📊";
}

.icon-cost::before {
    content: "💸";
}

.data-label {
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
}

.data-value {
    font-size: 24px;
    font-weight: 700;
    color: #1e40af;
}

/* 数据区块样式 */
.data-section {
    background: #f8fafc;
    border-radius: 10px;
    padding: 14px;
    border: 1px solid #e2e8f0;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: #1e3a8a;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #dbeafe;
}

.data-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    transition: all 0.2s ease;

    &:hover {
        background: #f0f9ff;
        border-color: #bae6fd;
    }
}

.list-label {
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
}

.list-value {
    font-size: 14px;
    color: #1e40af;
    font-weight: 600;
    background: #eff6ff;
    padding: 4px 12px;
    border-radius: 16px;
    border: 1px solid #dbeafe;
}

/* 价格网格样式 */
.price-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.price-item {
    background: white;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    border: 1px solid #e2e8f0;
    transition: all 0.3s ease;

    &:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
        border-color: #93c5fd;
    }
}

.price-label {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 8px;
    font-weight: 500;
}

.price-value {
    font-size: 20px;
    font-weight: 700;
    color: #1e40af;
    background: linear-gradient(135deg, #3b82f6 0%, #60a5fa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
</style>